<template>
	<view>
		<view class="fixed">
			<cu-custom :isBack="true">
				<block slot="backText"></block>
				<block slot="content">{{corpCode}}-SKU查询</block>
			</cu-custom>
		</view>
		<view class="cu-bar bg-white search fixed" :style="[{top:CustomBar + 'px'}]">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input @confirm="sub" v-model="asnId" type="text" placeholder="输入搜索的关键词" focus></input>
			</view>
			<view class="action" @click="toScan">
				<text class="cuIcon-scan" style="font-size: 56rpx;"></text>
			</view>
		</view>
		<scroll-view  scroll-y="true" class="indexes"  :scroll-with-animation="true"
		 :enable-back-to-top="true" :style="[{height:'calc(100vh - '+ CustomBar + 'px)'}]">
		<view style="font-size: 16px; background-color: #fff;margin-top: 10%;">
			<view class="padding" style="font-weight: 1000; font-size: 16px;">{{invname}}</view>
			<view class="padding">
				<view>图片：</view>
				<view class="padding">
					<image mode="widthFix" style="width: 100%;background-color: #eeeeee;" :src="skuInfo.skuImg" @click="imageClick(skuInfo.skuImg)"></image>
				</view>
				<view v-for="(item,index) in skuStock" :key="index">
					<view >{{item.warehouse_name}} 库存：</view>
					<view class="padding">
						{{item.stock_num}}
					</view>
				</view>
				<view>尺寸（长*宽*高）：</view>
				<view class="padding">
					{{skuInfo.length}} * {{skuInfo.width}} * {{skuInfo.height}}(mm)
				</view>
				<view>重量：</view>
				<view class="padding">
					{{skuInfo.weight}}g
				</view>
				<view>单据号：</view>
				<view class="padding">
					{{head.ccode}}
				</view>
				<view>单据类型：</view>
				<view class="padding">
					{{head.cbustype}}
				</view>
				<view>SKU所有货位号：</view>
				<view class="padding">
					<view class="text-content">
						{{skuInfo.skuLocations}}
					</view>
				</view>
				<view>本批次货位号：</view>
				<view class="padding">
					{{skuInfo.skuLocations}}
				</view>
				<!-- <view>申请个数：</view>
				<view class="padding">
					{{applic.prtqty}}
				</view>
				<view>申请人：</view>
				<view class="padding">
					{{applic.prtBy}}
				</view> -->
			</view>
		 </view>
		 </scroll-view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				asnId:'',
				CustomBar: this.CustomBar, //滚动定位用
				invcode:'',
				invname:'',
				head:'',
				applic:'',
				skuInfo:{},
				skuStock:[]
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'auditlist', 'corpCode']),
		},
		onLoad() {
			/* this.asnId = 'po_102_1000039326_1_1';
			this.sub(); */
		},
		methods: {
			imageClick(url){
				let listimg = [url];
				uni.previewImage({
					urls: listimg,
					current:url
				})
			},
			//点击导航栏 buttons 时触发
			sub(){
				let id = this.asnId;
				setTimeout(function(){
					// if(id.indexOf("dh") > -1 || id.indexOf("po") > -1){
					// 	this.invcode = id;
					// 	this.addinv();
					// }else if(id.indexOf("sc") > -1){
					// 	this.invcode = id;
					// 	this.addinv();
					// }else if(id.indexOf("dh") == -1){
					// 	this.asnId = '';
					// 	this.$api.msg('请扫描正确的条码!');
					// 	return;
					// }
					if(id){
						this.invcode = id;
						this.addinv();
					}else{
						this.asnId = '';
						this.$api.msg('请扫描正确的条码!');
						return;
					}
					
				}.bind(this),200);
			},
			//获取接口Sku
			httpGetSku(){
				//获取sku信息
				uni.request({
					url:this.serverURL_a+'/order/App/skuinfo',
					data:{
						cinvname:this.invname,
						__sid:this.userInfo.sessionid
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
					},
					method: 'POST',
					success:function(data){
						var invdata = data.data.resMap;
						var rem = JSON.parse(invdata)
						if(rem.success){
							this.skuInfo = rem.data.skuInfo;
							this.skuStock = rem.data.skuStock;
						}else{
							this.$api.msg(rem.message);
							return;
						}
					}.bind(this),
				});
			},
			cxScSku(invs){
				this.invname = invs.resMap.momOrderdetail.basInventory.cinvname;
				this.head = {
					ccode : invs.resMap.momOrderdetail.mocode,
					cbustype : "生产订单",
				}
				this.applic = {
					prtqty : invs.resMap.qty,
					prtBy : invs.resMap.createBy
				}
				this.httpGetSku();
			},
			cxPoSku(invs){
				this.invname = invs.resMap.basInventory.cinvname;
				this.head = {
					ccode : invs.resMap.pk.cpoid,
					cbustype : "采购订单",
				}
				this.applic = {
					prtqty : invs.resMap.iquantity,
					prtBy : invs.resMap.createBy
				}
				this.httpGetSku();
			},
			cxDhSku(invs){
				this.head = invs.resMap.hid;
				this.invname = invs.resMap.inventory.cinvname;
				//获取申请人
				uni.request({
					url:this.serverURL_a+'/order/App/getSkuDy',
					data:{
						attsid:invs.resMap.autoid,
						sign:this.invcode.split("_")[3],
						__sid:this.userInfo.sessionid
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
					},
					method: 'POST',
					success:function(data){
						var dy =  data.data;
						if(dy.code == '1001'){
							this.applic = dy.resMap;
						}else{
							this.$api.msg(invs.msg);
							return;
						}
					}.bind(this),
				});
				this.httpGetSku();
			},
			addinv(){
				// var url = this.serverURL_a+'/order/App/getSku';
				var url = this.serverURL_a+'/barcode/decode/querySku';
				
				var invs = this.invs;
				this.asnId = '';
				uni.request({
					url:url,
					data:{
						// autoid:this.invcode,
						__sid:this.userInfo.sessionid,
						barCode: this.invcode,
						needdjInfo: '1',
						// bneedStore: '0',
						// bmustAcct:'0'
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
					},
					method: 'POST',
					success:function(data){
						console.log(data,'data====');
						var res =  data.data;
						if(res.result=="false"){
							uni.showModal({
							  content: res.message,
							  showCancel:false,
							})
							return false;
						}
						this.invname = res.barCodeInfo.basInv.cinvname;
						this.head = {
							ccode : res.barCodeInfo.djno,
							cbustype : res.barCodeInfo.djType,
						}
						this.skuInfo = res.wmsSku.skuInfo || {};
						this.skuStock = res.wmsSku.skuStock || [];
						
						// if(invs.code == '1001'){
						// 	if(this.invcode.indexOf("sc") > -1){
						// 		this.cxScSku(invs);
						// 	}else if(this.invcode.indexOf("dh") > -1){
						// 		this.cxDhSku(invs);
						// 	}else{
						// 		this.cxPoSku(invs);
						// 	}
						// }else{
						// 	this.$api.msg(invs.msg);
						// 	return;
						// }
					}.bind(this),
					fail: function() {
						this.$api.msg('无法连接服务，请联系管理');
						this.isReC = false;
						return;
					}.bind(this)
				})
			},
			toScan(){
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						this.asnId = res.result;
						this.sub();
					}.bind(this)
				});
			},
		}
	}
</script>

<style lang="scss">
	.indexes {
		position: relative;
	}
	
	/* 底部栏 */
	.action-section{
		/* #ifdef H5 */
		/* #endif */
		position:fixed;
		left: 75%;
		bottom:30upx;
		z-index: 95;
		display: flex;
		align-items: center;
		background: rgba(255,255,255,.9);
		border-radius: 40upx;
		.checkbox{
			height:52upx;
			position:relative;
			image{
				width: 52upx;
				height: 100%;
				position:relative;
				z-index: 5;
			}
		}
		.clear-btn{
			position:absolute;
			left: 26upx;
			top: 0;
			z-index: 4;
			width: 0;
			height: 52upx;
			line-height: 52upx;
			padding-left: 38upx;
			font-size: $font-base;
			color: #fff;
			background: $font-color-disabled;
			border-radius:0 50px 50px 0;
			opacity: 0;
			transition: .2s;
			&.show{
				opacity: 1;
				width: 120upx;
			}
		}
		.total-box{
			flex: 1;
			display:flex;
			flex-direction: column;
			text-align:right;
			padding-right: 40upx;
			.price{
				font-size: $font-lg;
				color: $font-color-dark;
			}
			.coupon{
				font-size: $font-sm;
				color: $font-color-light;
				text{
					color: $font-color-dark;
				}
			}
		}
		.confirm-btn{
			padding: 0 38upx;
			margin: 0;
			border-radius: 100px;
			height: 76upx;
			line-height: 76upx;
			font-size: $font-base + 2upx;
			background: $uni-color-primary;
		}
	}

	.indexBar {
		position: fixed;
		right: 0px;
		bottom: 0px;
		padding: 20upx 20upx 20upx 60upx;
		display: flex;
		align-items: center;
	}

	.indexBar .indexBar-box {
		width: 40upx;
		height: auto;
		background: #fff;
		display: flex;
		flex-direction: column;
		box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
		border-radius: 10upx;
	}

	.indexBar-item {
		flex: 1;
		width: 40upx;
		height: 40upx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 24upx;
		color: #888;
	}

	movable-view.indexBar-item {
		width: 40upx;
		height: 40upx;
		z-index: 9;
		position: relative;
	}

	movable-view.indexBar-item::before {
		content: "";
		display: block;
		position: absolute;
		left: 0;
		top: 10upx;
		height: 20upx;
		width: 4upx;
		background-color: #f37b1d;
	}

	.indexToast {
		position: fixed;
		top: 0;
		right: 80upx;
		bottom: 0;
		background: rgba(0, 0, 0, 0.5);
		width: 100upx;
		height: 100upx;
		border-radius: 10upx;
		margin: auto;
		color: #fff;
		line-height: 100upx;
		text-align: center;
		font-size: 48upx;
	}
</style>
